package LeetCode.tree;

import java.util.LinkedList;
import java.util.List;

public class RuValidBinSearchTree {
   static  List<Integer> ans =  new LinkedList<Integer>();
    public static void inorder(BinSearchTree node){
        if(node != null) {
            inorder(node.left);
            ans.add(node.data);
            inorder(node.right);
        }
    }

    public static boolean isvalid(){
        if(ans.size()<2){
            return true;
        }
        for(int i=0;i<ans.size()-1;i++){
            if(ans.get(i)>ans.get(i+1)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        BinSearchTree node = BinSearchTree.createBintree();
        RuValidBinSearchTree.inorder(node);
        System.out.println(RuValidBinSearchTree.isvalid());
    }
}
